<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>后台管理-登陆</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/style/loginAdmin.css" media="all">
</head>
<body>
<div id="container">
    <div></div>
    <div class="admin-login-background">
        <!--<div class="admin-header">-->
        <!--<img src="image/ex_logo.png" class="admin-logo">-->
        <!--</div>-->

        <div>
            <i class="layui-icon layui-icon-username admin-icon admin-icon-username"></i>
            <input type="text" name="username" placeholder="请输入用户名" id="username"
                   autocomplete="off"
                   required="required"
                   class="layui-input admin-input admin-input-username">
        </div>
        <div>
            <i class="layui-icon layui-icon-password admin-icon admin-icon-password"></i>
            <input type="password" name="password" id="password"
                   placeholder="请输入密码"
                   autocomplete="off"
                   required="required"
                   class="layui-input admin-input">
        </div>
        <!--<div>-->
        <!--<input type="text" name="vCode"-->
        <!--placeholder="请输入验证码"-->
        <!--autocomplete="off"-->
        <!--required="required"-->
        <!--class="layui-input admin-input admin-input-verify">-->
        <!--<img class="admin-captcha"  src="/index/getVcode" id="code"-->
        <!--onclick="updateVerify(this)">-->
        <!--</div>-->
        <button class="layui-btn admin-button" id="loginSub">登陆</button>
    </div>
</div>

<script src="/static/layui/layui.all.js"></script>
<script src="/static/js/jquery.min.js" media="all"></script>
<script src="/static/js/jquery.cookie.js" media="all"></script>

<script>
    // $(function(){
    //   let img = document.getElementById('code');
    //   img.src = '/index/getVcode?rnd=' + Math.random();
    // });
    function updateVerify() {
        let img = document.getElementById('code');
        img.src = '/index/getVcode?rnd=' + Math.random();
    }

    $('#loginSub').on('click', function () {
        if ($('#username').val() != '' && $('#password').val() != '') {
            $.ajax({
                url: '/index/login',
                method: 'POST',
                data: {username: $('#username').val(), password: $('#password').val()},
                success: (result) => {
                    if (result == 0) {
                        layer.msg('登录失败，账号或密码错误！');
                    } else if (result == 2) {
                        layer.msg('登录失败，数据库连接错误！');
                    } else {
                        layer.msg('登录成功！');
                        setTimeout(function () {
                            window.location.href = '/index/index';
                        }, 1000);
                    }
                }
            });
        }
    })


</script>
</body>
</html>
